<template>
  <div class="desk-lock" @click="isLock = false" @keydown="isLock = false">
    <div class="filter-modal" :class="{ filter: !isLock }"></div>
    <template v-if="isLock">
      <div class="date">
        <p class="fs120 fw100">{{ $dateFormat('hh:mm') }}</p>
        <p class="fs50 fw400">{{ $dateFormat('YYYY年MM月') }}</p>
      </div>
    </template>
    <template v-else>
      <div class="login">
        <img src="@/assets/images/account.png" alt="account" />
        <div class="fs30 pt20 pb20 fw300">Fivexu</div>
        <div class="password">
          <input
            v-model="password"
            autofocus
            placeholder="输入密码"
            :type="showPassword ? 'text' : 'password'"
            @keydown.enter="handleLoginDesk"
          />
          <em :class="{ ac: showPassword }" @mousedown="handleMousedown">
            <i class="iconfont wos-eye" />
          </em>
          <span @click.stop="handleLoginDesk">
            <i class="iconfont wos-to-right-line" />
          </span>
        </div>
      </div>
    </template>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useSystemSettingStore } from '@/stores/desk/systemSetting'

const systemSettingStore = useSystemSettingStore()
const isLock = ref<boolean>(true)
const showPassword = ref<boolean>(false)
const password = ref<string>('admin')

const handleMouseup = () => {
  showPassword.value = false
  document.removeEventListener('mouseup', handleMouseup)
}

const handleMousedown = () => {
  showPassword.value = true
  document.addEventListener('mouseup', handleMouseup)
}

const handleLoginDesk = () => {
  if (password.value === 'admin') {
    systemSettingStore.setDeskLock(false)
  }
}
</script>

<style scoped lang="scss">
@import '@/assets/scss/common';

.desk-lock {
  color: #fff;
  position: fixed;
  z-index: $z-index-window-lock;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  background: url('@/../public/lock.jpg') no-repeat center center / cover;

  &.lock-enter-from {
    opacity: 0.5;
    transform: scale(1.5);
  }

  &.lock-enter-active,
  &.lock-leave-active {
    transition: all 0.5s;
  }

  &.lock-leave-to {
    transform: translateY(-100%);
  }

  .filter-modal {
    position: absolute;
    left: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    transition: all 0.3s;

    &.filter {
      backdrop-filter: blur(10px);
    }
  }

  .date {
    position: absolute;
    z-index: 10;
    left: 40px;
    bottom: 10vh;
  }

  .login {
    text-align: center;
    position: absolute;
    z-index: 10;
    left: 50%;
    top: 50%;
    transform: translate3d(-50%, -50%, 0);

    img {
      width: 220px;
      height: 220px;
      object-fit: contain;
    }

    .password {
      position: relative;

      &:hover {
        input {
          border-color: transparent;
        }
      }

      input {
        background-color: #fff;
        outline: none;
        width: 100%;
        height: 32px;
        border: 2px solid #999;
        padding-right: 80px;
        padding-left: 10px;
        box-sizing: border-box;
        font-size: 16px;
      }

      em {
        display: inline-flex;
        justify-content: center;
        align-items: center;
        width: 40px;
        height: 28px;
        position: absolute;
        right: 42px;
        top: 2px;
        color: #ccc;

        &.ac {
          color: #fff;
          background-color: var(--theme-color);
        }
      }

      > span {
        display: inline-flex;
        justify-content: center;
        align-items: center;
        width: 40px;
        height: 28px;
        position: absolute;
        right: 2px;
        top: 2px;
        background-color: #ccc;
      }
    }
  }
}
</style>
